package com.matrix.framework.sysconfig.iplist.repository;

import com.matrix.framework.sysconfig.iplist.data.IpSecurityRulePo;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Flux;

/**
 * IP安全规则Repository接口
 *
 * Copyright © 海平面工作室 版权所有
 *
 * @Author: Leo
 * @Create: 2024/12/1 15:30
 * @Since 1.2
 */
public interface IpSecurityRuleRepository extends ReactiveCrudRepository<IpSecurityRulePo, Long> {

    /**
     * 查找所有启用的规则
     */
    @Query("SELECT * FROM security_ip_rule WHERE enabled = true ORDER BY create_time DESC")
    Flux<IpSecurityRulePo> findEnabledRules();

    /**
     * 根据IP模式和规则类型查找规则
     */
    @Query("SELECT * FROM security_ip_rule WHERE ip_pattern = :ipPattern AND rule_type = :ruleType AND enabled = true")
    Flux<IpSecurityRulePo> findByIpPatternAndType(String ipPattern, String ruleType);

    /**
     * 根据规则类型查找规则
     */
    @Query("SELECT * FROM security_ip_rule WHERE rule_type = :ruleType AND enabled = true")
    Flux<IpSecurityRulePo> findByRuleType(String ruleType);

    /**
     * 根据目标类型查找规则
     */
    @Query("SELECT * FROM security_ip_rule WHERE target_type = :targetType AND enabled = true")
    Flux<IpSecurityRulePo> findByTargetType(String targetType);
} 